var app = getApp();
Page({
    data:{
        curPage : "/zofui_sales/cut/list",
        page : {
            isend : false,
            doing : false,
            doo : 'cut',
            pdata : {
                op : 'list',
                page : 1,
                sortid : 0,
                otype:0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        Menu: [{
            url: "/zofui_sales/pages/index/index",
            iconPath: "/images/tabbar01.png",
            selectedIconPath: "/images/tabbar01_on.png",
            title: "首页",
            type: "tabbar"
        }, {
            url: "/zofui_sales/cut/list",
            iconPath: "/images/tabbar06.png",
            selectedIconPath: "/images/tabbar06_on.png",
            title: "砍价"
        }, {
            url: "/zofui_sales/cut/mylist",
            iconPath: "/images/tabbar05.png",
            selectedIconPath: "/images/tabbar05_on.png",
            title: "记录"
        }, {
            url: "/zofui_sales/pages/user/user",
            iconPath: "/images/tabbar07.png",
            selectedIconPath: "/images/tabbar07_on.png",
            title: "我的",
            type: "tabbar"
        }],
        isIPX : app.globalData.isIPX,
        sort : [],
        showselect : false,
        showtoptab : true,
        showsortid : 'sortid0',
        ordertype : [{name:'距离最近',id:0},{name:'参与最多',id:1},{name:'底价最低',id:2}],
        goodstype : [
            {name:'进行中的',id:1},
            {name:'已经结束',id:2},
            {name:'还未开始',id:3},
        ],
        tablist : [
            {name:'减价分类',id:4,icon:'zan-icon-arrow',rotate:true},
            {name:'离我最近',id:1,icon:'zan-icon-arrow',rotate:true},
            {name:'减价状态',id:2,icon:'zan-icon-arrow',rotate:true},
            {name:'浏览模式',id:3,icon:'zan-icon-wap-nav',rotate:false},
        ],
        sorttwo : [],
        color : '',
        tab0name : '减价分类',
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;

        var zfid = options.zfid ? options.zfid : '';
        var shopid = options.shopid ? options.shopid : 0;
        self.setData({
            'page.pdata.sortid' : options.status ? options.status : 0,
            'page.pdata.shopid' : shopid,
            'page.pdata.page' : 1,
            'page.pdata.zfid' : zfid,
            'page.pdata.isinit' : 0,
        });
        self.data.options = options;

        app.com.getLocation(self,function(loc){
            self.setData({
                'page.pdata.lat' : loc.latitude,
                'page.pdata.lng' : loc.longitude,
            });
            app.com.auth(function(user){
                app.com.getPage(self,self.data.page,20,function(res){
                    var data = res.data.data;
                    var color = app.com.mainColor(data.params.style);

                    self.setData({
                        datalist : data.list,
                        Pagetheme : res.data.data.params.style,
                        sharedata : res.data.data.sharedata,
                        sort : data.sort,
                        params : data.params,
                        'page.pdata.isinit' : 1,
                        citylist : data.citylist ? data.citylist : [],
                        tab0name : data.sname,
                        inited : true,
                        color : color,
                    });
                    if(data.params.shopnav == 1 && shopid > 0){
                        self.setData({
                            'Menu[0].url' : '/zofui_sales/shop/shop?id='+shopid,
                            'Menu[2].url' : '/zofui_sales/cut/mylist?shopid='+shopid,
                        })
                    }
                    
                    wx.setNavigationBarColor({
                        frontColor: '#ffffff',
                        backgroundColor: color,
                    });
                    wx.setNavigationBarTitle({
                      title:  res.data.data.params.title ? res.data.data.params.title : '减价',
                    });

                },false,function(res){
                    app.com.alert(res.data.message);
                });
            });
        });
       
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.isdown = true;
        this.onLoad( this.data.options );
        wx.stopPullDownRefresh();
    },
    listtypefn(e){
        this.setData({
           listtype : e.detail
        })
    },
    setList(e){
        var self = this;
        var setdata = {
            datalist : [],
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        };
        for (var t in e.detail) {
            setdata[t] = e.detail[t];
        }
        self.setData(setdata);
        
        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
        });
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    }

})